/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 30318
 * Date: 2023-11-28
 * Time: 16:30
 */
public class Fan {
    private String brand;
    private String status;
    private int speed;

    public Fan(String brand) {
        this.brand = "格力";
        this.status = "stop";
        this.speed = 0;
    }

    public void switchFan() {
        if (status.equals("ready")) {
            status = "working";
        } else {
            status = "ready";
        }
    }

    public void increaseSpeed() {
        if (speed < 3) {
            speed++;
        } else {
            System.out.println("当前风速已是最高档，无法加速！");
        }
    }

    public void decreaseSpeed() {
        if (speed > 0) {
            speed--;
        } else {
            System.out.println("当前风扇属于停止状态，无法减速！");
        }
    }

    public String getState() {
        return "Brand: " + brand + ", Status: " + status + ", Speed: " + speed;
    }

    public static void main(String[] args) {
        //创建一个电风扇对象，用ｆ表示；
        Fan f = new Fan("格力");
        //加速一次电风扇；
        f.increaseSpeed();
        //向控制台输出f的状态和速度
        System.out.println(f.getState());
        //启动电风扇(调用对象的开关方法)
        f.switchFan();
        //向控制台输出f的状态和速度
        System.out.println(f.getState());
        //连续加速４次(考虑发生什么情况)
        for (int i = 0; i < 4; i++) {
            f.increaseSpeed();
        }
        //向控制台输出f的状态和速度
        System.out.println(f.getState());
        //连续减速４次(考虑发生什么情况)
        for (int i = 0; i < 4; i++) {
            f.decreaseSpeed();
        }
        //向控制台输出f的状态和速度
        System.out.println(f.getState());
        //关掉电风扇(调用对象的开关方法)
        f.switchFan();
        //连续加速2次
        for (int i = 0; i < 2; i++) {
            f.increaseSpeed();
        }
        //向控制台输出f的状态和速度
        System.out.println(f.getState());
    }
}